<template>
  <page-header-wrapper>
    <application-search :filterFields="['CityRfyResult']" @search="handleSearch" @reset="handleReset">
    </application-search>
    <a-card :bordered="false">
      <s-table
        :scroll="{ x: 2800 }"
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <div slot="tabAction">
          <buttonSelect
            class="m-l-10"
            v-model="typeSelect"
            :options="[
              { value: '', label: '全部' },
              { value: '符合', label: '符合' },
              { value: '不符合', label: '不符合' },
              { value: '未审批', label: '未审批' },
            ]"
            @change="handleButtonSelectChange"
          ></buttonSelect>
        </div>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
          <y-button v-if="diffDays(record.CityRfyDate) <= 16" type="link" @click="handleAudit(record.ID)"
            >审批</y-button
          >
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, buttonSelect, applicationSearch } from '@/components'
import { getProposerList } from '@/api/common'
import moment from 'moment'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    applicationSearch,
  },
  computed: {
    textColor() {
      return function (text) {
        const classMap = new Map([
          ['符合', 'text-success'],
          ['不符合', 'text-error'],
          ['未审核', 'text-warning'],
          ['未审批', 'text-warning'],
        ])
        return classMap.get(text)
      }
    },
  },
  data() {
    this.$eventBus.$on('leaderAuditRefresh', () => {
      this.$refs.table.refresh()
    })
    return {
      typeSelect: '',
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'BossRfyEdit',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        {
          title: '保障类型',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '核定保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '信息',
          align: 'center',
          customRender: (text, record) => {
            const days = moment().diff(moment(record.ProcessDate), 'days')
            if (days <= 16) {
              return <span class="text-success">正常流程</span>
            } else {
              return <span class="text-error">信息超期{days - 16}天</span>
            }
          },
        },
        {
          title: '市审核结果',
          align: 'center',
          dataIndex: 'CityVfyResult',
          customRender: (text) => <span class={this.textColor(text || '未审核')}>{text || '未审核'}</span>,
        },
        {
          title: '审批结果',
          align: 'center',
          dataIndex: 'CityRfyResult',
          customRender: (text) => <span class={this.textColor(text || '未审批')}>{text || '未审批'}</span>,
        },
        {
          title: '市级审核人',
          align: 'center',
          dataIndex: 'CityVfyAgent',
        },
        {
          title: '审核日期',
          align: 'center',
          dataIndex: 'CityVfyDate',
          customRender: (text) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
        },
        {
          title: '区县',
          align: 'center',
          dataIndex: 'RegionName',
          customRender: (text) => {
            return <ellipsis length={16}>{text}</ellipsis>
          },
        },
        {
          title: '街道办事处',
          align: 'center',
          dataIndex: 'TownshipName',
          customRender: (text) => {
            return <ellipsis length={16}>{text}</ellipsis>
          },
        },
        {
          title: '配租方式',
          align: 'center',
          dataIndex: 'CityVfyAssign',
        },
        {
          title: '审批日期',
          align: 'center',
          dataIndex: 'CityRfyDate',
          customRender: (text) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
        },
        {
          title: '操作',
          align: 'center',
          width: '180px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        requestParameters.strContent.CityRfyResult = this.typeSelect
        return getProposerList(requestParameters).then((res) => {
          return res
        })
      },
      selectedRowKeys: [],
    }
  },
  methods: {
    diffDays(day) {
      return moment().diff(moment(day), 'days')
    },
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.typeSelect = ''
      this.$refs.table.refresh(true)
    },
    handleButtonSelectChange() {
      this.$refs.table.refresh(true)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'cityComplexInquireDetail',
        params: {
          id,
        },
      })
    },
    handleAudit(id) {
      this.$router.push({
        name: 'leaderNewReviewManageAudit',
        params: {
          id,
          type: 'leader',
        },
      })
    },
  },
}
</script>
<style lang="less" scoped></style>
